package com.link.cloud.business.test.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.link.cloud.business.test.bean.Student;
import com.link.cloud.business.test.service.StudentService;
import com.link.cloud.page.Paging;

@RestController
@RequestMapping("/student")
public class StudentController {
	
	private static Logger logger = LoggerFactory.getLogger(StudentController.class);
	
	@Autowired
	private StudentService studentService;
	
	@RequestMapping(value="/findAll",method=RequestMethod.POST,produces = {"application/json;charset=utf-8"})
	public String findAll(int pageNum,int pageSize){
		logger.info("-------------enter into controller");
		Map<String,Object> result = new HashMap<String,Object>();
		Paging<Student> page = studentService.findAll(pageNum,pageSize);
		result.put("students", page);
		return JSON.toJSONString(result);
	}
	
	@RequestMapping(value="/findByPage",method=RequestMethod.GET,produces = {"application/json;charset=utf-8"})
	public Paging<Student> findByPage(int pageNum,int pageSize){
		logger.info("-------------enter into get controller");
		Paging<Student> page = studentService.findAll(pageNum,pageSize);
		return page;
	}

}
